﻿<%@ page contentType="text/html; charset=utf-8" language="java" %>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Properties"%>
<%@page import="java.io.IOException"%>
<%@page import="java.io.FileNotFoundException"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.File"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.util.Collections"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList;"%>
<% 
String path = request.getContextPath();
InputStream inputStream;
String optionString = "";
List<String> list = new ArrayList<String>();
		try {
			String strFile = "pattens" + File.separator
					+ "crawl.patten";
			File file = new File(strFile);

			File fileDirs = new File(file.getParent());
			if (!fileDirs.exists()) {
				fileDirs.mkdirs();
			}

			if (!file.exists()) {

				file.createNewFile();
			}
			System.out.println(file.getAbsolutePath());

			inputStream = new FileInputStream(strFile);

			Properties properties = new Properties();

			properties.load(inputStream);
			Iterator iterator = properties.keySet().iterator();
			while (iterator.hasNext()) {
			String pattenName = (String) iterator.next();
			list.add(pattenName);
		}
		Collections.sort(list);
		optionString = optionString + "<option value= '" + "'>" + "none" + "</option>";
					
		for (int i = 0; i < list.size(); i++) {
			String pattenName = list.get(i);
			String pattenValue = properties.getProperty(pattenName);
			optionString = optionString + "<option value= '" + pattenValue
					+ "'>" + pattenName + "</option>";
		}

		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/startDate.js"></script>
<script type="text/javascript" src="js/seedList.js"></script>
<link href="<%=path%>/css/admin.css" rel="stylesheet" type="text/css"/>
<title>分布式爬虫后台管理</title>
<script type="text/javascript" language="javascript">
var checknode="random";
function getRadioValue(radioName){
 var obj=document.getElementsByName(radioName);   
        for(var i=0;i<obj.length;i++){   
        if(obj[i].checked){ 
            checknode  =  obj[i].id
            return checknode;   
            }   
        }  
 }
 function checkMatchRadio(){
    var checkval = getRadioValue("nodecheck");
    if( checkval=="oppoint"){
      document.getElementById("match_list_id").style.display = "";
      document.getElementById("match_id").style.display = "none";
    }else{
      document.getElementById("match_id").style.display = "";
      document.getElementById("match_list_id").style.display = "none";
    }
    
 }
 
 function checkFilterRadio(){
    var checkval = getRadioValue("nodecheck");
    if( checkval=="oppoint"){
      document.getElementById("filter_list_id").style.display = "";
      document.getElementById("filter_id").style.display = "none";
    }else{
      document.getElementById("filter_id").style.display = "";
      document.getElementById("filter_list_id").style.display = "none";
    }
    
 }
 
 function adosubmit(){
    var mysel=document.getElementById("freddnodes");    
    var txt=mysel.options[mysel.options.selectedIndex].text;                                                                     //获取下拉列表框显示的文本 
    
    document.forms[0].action="./setnodecheckval2.jsp?checknode="+checknode+"&checkval="+txt;
    document.forms[0].submit();
 }
 

 
  
  /**
  * 添加需要匹配的正则
  */
  function addMatchPatten(){
  
  //获取隐藏框的句柄
  var hiddenMatch = document.getElementById("hiddenMatch_id");
  //先清空隐藏框中的字符
  hiddenMatch.value = "";
  
  var checkval = getRadioValue("nodecheck");
   var oOption = document.createElement("option");
    if( checkval=="oppoint"){
     oOption.text = document.getElementById("match_list_id").value;
         oOption.value = document.getElementById("match_list_id").value;
         document.all.match_list_all.add(oOption);
    }else{
      oOption.text = document.getElementById("match_id").value;
         oOption.value = document.getElementById("match_id").value;
         document.all.match_list_all.add(oOption);
         document.all.match_id.value = "";
    }
    
    //循环遍历列表 将所有内容加入到隐藏的输入框中
     var obj = document.getElementById("match_list_all_id").options;
         for(var i=0;i<obj.length;i++)
         {
           hiddenMatch.value = obj.options[i].value+","+hiddenMatch.value;
         }
         
         alert(hiddenMatch.value);
    
 }
 
   /**
  * 删除需要匹配的正则
  */
  function delMatchPatten(){
  //获取隐藏框的句柄
  var hiddenMatch = document.getElementById("hiddenMatch_id");
  //先清空隐藏框中的字符
  hiddenMatch.value = "";
  
  //删除列表中的内容
  var oSelect = document.all.match_list_all;
     for(var i=0; i<oSelect.options.length; i++)
     {
         if(i>=0 && i<=oSelect.options.length-1 && oSelect.options[i].selected)
         {
             oSelect.options[i] = null;
             i --;
         }
     }
     
     //循环遍历列表 将所有内容加入到隐藏的输入框中
     var obj = document.getElementById("match_list_all_id").options;
         for(var i=0;i<obj.length;i++)
         {
           hiddenMatch.value = obj.options[i].value+","+hiddenMatch.value;
         }
         alert(hiddenMatch.value); 
  }
  /**
  * 添加需要过滤的正则
  */
  function addFilterPatten(){
  //获取隐藏框的句柄
  var hiddenFilter = document.getElementById("hiddenFilter_id");
  //先清空隐藏框中的字符
  hiddenFilter.value = "";
  var checkval = getRadioValue("nodecheck");
      var oOption = document.createElement("option");
    if( checkval=="oppoint"){
     oOption.text = document.getElementById("filter_list_id").value;
         oOption.value = document.getElementById("filter_list_id").value;
         document.all.filter_list_all.add(oOption);
    }else{
      oOption.text = document.getElementById("filter_id").value;
         oOption.value = document.getElementById("filter_id").value;
         document.all.filter_list_all.add(oOption);
         document.all.filter_id.value = "";
    } 
    
      //循环遍历列表 将所有内容加入到隐藏的输入框中
     var obj = document.getElementById("filter_list_all_id").options;
         for(var i=0;i<obj.length;i++)
         {
           hiddenFilter.value = obj.options[i].value+","+hiddenFilter.value;
         }
         
         alert(hiddenFilter.value);
        
 }
 
 /**
  * 删除需要过滤的正则
  */
  function delFilterPatten(){
  //获取隐藏框的句柄
  var hiddenFilter = document.getElementById("hiddenFilter_id");
  //先清空隐藏框中的字符
  hiddenFilter.value = "";
  
  //删除列表中的内容
  var oSelect = document.all.filter_list_all;
     for(var i=0; i<oSelect.options.length; i++)
     {
         if(i>=0 && i<=oSelect.options.length-1 && oSelect.options[i].selected)
         {
             oSelect.options[i] = null;
             i --;
         }
     }
     
      //循环遍历列表 将所有内容加入到隐藏的输入框中
     var obj = document.getElementById("filter_list_all_id").options;
         for(var i=0;i<obj.length;i++)
         {
           hiddenFilter.value = obj.options[i].value+","+hiddenFilter.value;
         }
         alert(hiddenFilter.value);
  }
/**
  * 删除选定项目
  *
  * oSelect: 源列表框对象 
  */
 function deleteSelectItem(oSelect)
 {
     for(var i=0; i<oSelect.options.length; i++)
     {
         if(i>=0 && i<=oSelect.options.length-1 && oSelect.options[i].selected)
         {
             oSelect.options[i] = null;
             i --;
         }
     }
 }
   </script>
</head>

<body>
<!--heaer start-->
<div class="header"><img src="../images/SystemName.gif" /></div>
<!--heaer end-->
<!--content start-->
<div class="content">
   <jsp:include page="/page/left_menu_admin.jsp" />  
	<div class="right">
	    <div class="label">
		    <ul>
			     <li class="onover"><a href="">新建任务</a></li>
			</ul>
	    </div>
	    <form name="form1" method="post" action="newtaskAction.jsp">
		<div class="info">
		  <table width="800" border="0" cellpadding="0" cellspacing="0">
			  <tr>
				<td width="190" align="right"><strong>任务名称：</strong></td>
				<td width="594"><input class="input" type="text" name="name"/></td>
			  </tr>
			  <tr>
				<td align="right"><strong>抓取深度：</strong></td>
				<td><input class="input" type="text" name="deep"  value="0" 
			onkeydown="value=value.replace(/[^\d]/, '')" 
			onkeyup="value=value.replace(/[^\d]/, '')"/></td>
			  </tr>
			 <tr>
				<td width="210" align="right">页面解析方式：</td>
				<td width="202"><select style="height:20px;width:100px;" size="1" name="extractorType">
				<option value="static">静态</option>
			    <option value="dynamic">动态</option>
			    </select></td>
				<td></td>
			</tr>
		  </table>
		</div>
		<div class="info">
		  <table width="800" border="0" cellpadding="0" cellspacing="0">
			  <tr>
				<td width="210" align="right">起始种子页面：</td>
				<td width="202"><input class="input" type="text" name="seed" id="seed_id" />
				<input type="hidden" name="hiddenSeeds" id="hiddenSeeds_id"/></td>
				<td></td>
			  </tr>
			  <tr>
				<td align="right">当前已选择的种子页：</td>
				<td><select class="liebiao" name="seed_list" size="5" id="seed_list_id" multiple="multiple" style="width:100px; "></select></td>
				<td width="405">
				<input class="button" type="button" value="添加" onClick="addSeed()"/><br />
				<input class="button" type="button" value="删除" onClick="delSeed()"/></td>
			  </tr>
		  </table>
		</div>
		<div class="info">
		  <table width="800" border="0" cellpadding="0" cellspacing="0">
			  <tr>
				<td width="210" align="right">请选择需要匹配的正则：</td>
				<td width="202">
				<input type="hidden" name="hiddenMatch" id="hiddenMatch_id"/>
				<input id="random" name="nodecheck" type="radio" checked="checked" onClick="checkMatchRadio();"/>手动输入</td>
				<td><input type="text" name="match" id="match_id" style="display:none"/>
				</td>
				</tr>
				<tr>
				<td></td>
				<td><input id="oppoint" name="nodecheck" type="radio" onClick="checkMatchRadio();"/>从正则库中选择</td>
				<td><select name="match_list" id="match_list_id" style="display:none;">
				<%= optionString %>
				</select></td>
			    </tr>
			  <tr>
				<td align="right">当前已选择需要匹配的正则:</td>
				<td><select class="liebiao" name="match_list_all" size="5" id="match_list_all_id" multiple="multiple" style="width:100px; "></select></td>
				<td width="405">
				<input class="button" type="button" value="添加" onClick="addMatchPatten()"/><br />
				<input class="button" type="button" value="删除" onClick="delMatchPatten()"/></td>
			  </tr>
		  </table>
		</div>
		<div class="info">
		  <table width="800" border="0" cellpadding="0" cellspacing="0">
			  <tr>
				<td width="210" align="right">请选择需要过滤的正则：</td>
				<td width="202">
				<input type="hidden" name="hiddenFilter" id="hiddenFilter_id"/>
				<input id="random" name="nodecheck" type="radio" checked="checked" onClick="checkFilterRadio();"/>手动输入</td>
				<td><input type="text" name="filter" id="filter_id" style="display:none"/>
				</td>
				</tr>
				<tr>
				<td>
				</td><td>
				<input id="oppoint" name="nodecheck" type="radio" onClick="checkFilterRadio();"/>从正则库中选择</td>
				<td><select name="filter_list" id="filter_list_id" style="display:none;">
				<%= optionString %>
				</select>
				</td>
			  </tr>
			  <tr>
				<td align="right">当前已选择需要过滤的正则:</td>
				<td><select class="liebiao" name="filter_list_all" size="5" id="filter_list_all_id" multiple="multiple" style="width:100px; "></select></td>
				<td width="405">
				<input class="button" type="button" value="添加" value="添加" onClick="addFilterPatten()"/><br />
				<input class="button" type="button" value="删除" value="删除" onClick="delFilterPatten()"/></td>
			  </tr>
		  </table>
		</div>
		<div class="info">
		  <table width="800" border="0" cellpadding="0" cellspacing="0">
			  <tr>
				<td width="210" align="right">连接超时时间：</td>
				<td width="202"><input class="input" type="text" name="connectiontimeout"  
			    value="2000" 
			    onkeydown="value=value.replace(/[^\d]/, '')" 
			    onkeyup="value=value.replace(/[^\d]/, '')"/></td>
				<td></td>
			  </tr>
			  <tr>
				<td width="210" align="right">流读取超时时间：</td>
				<td width="202"><input class="input" type="text" name="sockettimeout"  
			    value="20000" 
			    onkeydown="value=value.replace(/[^\d]/, '')" 
			    onkeyup="value=value.replace(/[^\d]/, '')"/></td>
				<td></td>
			  </tr>
			  <tr>
				<td width="210" align="right">设定启动时间：</td>
				<td width="202"><input class="input" type="text" name="textfield"   onFocus="CalendarWebControl.show(this,true,this.value);"/></td>
				<td></td>
			  </tr>
			  <tr>
				<td width="210" align="right">运行周期(单位：天)：</td>
				<td width="202"><input class="input" type="text" name="interval"
			    value="360" 
			    onkeydown="value=value.replace(/[^\d]/, '')" 
			    onkeyup="value=value.replace(/[^\d]/, '')"
				/></td>
				<td></td>
			  </tr>
			  <tr>
				<td width="210" align="right">启动节点数：</td>
				<td width="202"><input class="input" type="text" name="nodeCount"
			    value="1" onkeydown="value=value.replace(/[^\d]/, '')" 
			    onkeyup="value=value.replace(/[^\d]/, '')" /></td>
				<td></td>
			  </tr> 
			  <tr>
				<td width="210" align="right">下载到本地的文件保存路径：</td>
				<td width="202"><input class="input" type="text" name="filepath" value="../mirror/"/></td>
				<td></td>
			  </tr>
			  <tr>
				<td width="210" align="right">当节点数不够时是否运行：</td>
				<td width="202"><select style="height:20px;width:100px;" size="1" name="scalable">
				<option value="YES">运行</option>
			    <option value="NO">等待</option>
				</select></td>
				<td></td>
			  </tr>
			  <tr>
				<td width="210" align="right">是否需要根据硬件资源进行速度调整：</td>
				<td width="202"><select style="height:20px;width:100px;" size="1" name="startHardwareAdjust">
				<option value="NO">不需要</option>
			    <option value="YES">需要</option>
			    </select></td>
				<td></td>
			  </tr>
			  <tr>
				<td width="210" align="right">是否需要保存链接中的图片：</td>
				<td width="202"><select style="height:20px;width:100px;" size="1" name="needImgs">
				<option value="NO">不需要</option>
			    <option value="YES">需要</option>
				</select></td>
				<td></td>
			  </tr>
			  <tr>
				<td width="210" align="right">是否需要启动更新模块：</td>
				<td width="202"><select style="height:20px;width:100px;" size="1" name="startUpdate">
				<option value="NO">不需要</option>
			    <option value="YES">需要</option>
				</select></td>
				<td></td>
			  </tr>
			  <tr>
				<td width="210" align="right">设置智能COOKIE使用方式：</td>
				<td width="202">
				<select style="height:20px;width:100px;" size="1" name="intelligentCookieType">
				<option value="none">不使用</option>
			    <option value="intelligent">智能存储</option>
			    <option value="random">随机存储</option>
				</select></td>
				<td></td>
			  </tr>
		  </table>
		</div>
		<div class="info" style="text-align:center;">
		<input class="button" type="submit" value="提交" />&nbsp;&nbsp;&nbsp;
		<input class="button" type="reset" value="重置" /></div>
		</form>
	</div>
	<div class="clear"></div>
</div>
<!--content end-->
<div class="footer"></div>
</body>
</html>
